package com.ruoyi.web.runner;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 系统启动完成,自动执行run()
 */
@Component
@Order(1)
public class ProjectBaseMsgRunner implements ApplicationRunner {

    private static final Logger log = LoggerFactory.getLogger(ProjectBaseMsgRunner.class);

    /**
     * 端口号
     */
    @Value("${server.port}")
    private String port;

    /**
     * 项目路径
     */
    @Value("${server.servlet.context-path}")
    private String contextPath;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 项目启动后执行该方法

        try {

            // 获取本机内网ip
            String ip = InetAddress.getLocalHost().getHostAddress();
            if (ip.indexOf("127.0.0.1") <= -1) {
                ip = "127.0.0.1";
            }
            String address = "http://" + ip + ":" + port + contextPath;
            log.info("后台登录地址:" + address);
            log.info("swagger接口地址:" + address + "/swagger-ui/index.html");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
